<div class="mat-elevation-z1">
  <mat-toolbar>
    <span class="toolbar-title">历史策略</span>
    <mat-button-toggle-group [(ngModel)]="filterForm['ex']"
                             (change)="filter()">
      <mat-button-toggle value="all">全部</mat-button-toggle>
      <mat-button-toggle [value]="ex.code" *ngFor="let ex of $exchs | async">
        {{ex.name}}
      </mat-button-toggle>
    </mat-button-toggle-group>
    <span class="spacer"></span>
  </mat-toolbar>

  <div class="table-filter-form">

    <div>
      <span class="field-label subordinated">基础币种</span>
      <button mat-button [color]="filterForm['baseCcy']===ccy? 'accent':null" *ngFor="let ccy of $ccyCodes | async"
              (click)="baseCcySelected(ccy)">
        <img class="ccy-logo" [src]="CoinLogoPath(ccy)" alt="">
        {{ccy}}
      </button>
    </div>

    <div class="operation-bar">
      <div class="form-field">
        <span class="label subordinated">方向</span>
        <mat-button-toggle-group [(ngModel)]="filterForm['side']" (change)="filter()">
          <mat-button-toggle value="all">不限</mat-button-toggle>
          <mat-button-toggle value="buy">买入</mat-button-toggle>
          <mat-button-toggle value="sell">卖出</mat-button-toggle>
        </mat-button-toggle-group>
      </div>

      <!--<mat-form-field>
        <mat-label>类型</mat-label>
        <mat-select [(ngModel)]="filterForm['type']">
          <mat-option value="all">不限</mat-option>
          <mat-option *ngFor="let strategyType of strategyTypes" [value]="strategyType.value">
            {{strategyType.label}}
          </mat-option>
        </mat-select>
      </mat-form-field>-->

      <mat-form-field>
        <input matInput placeholder="基础币种" name="baseCcy" [(ngModel)]="filterForm['baseCcy']"
               (keyup.enter)="filter()">
      </mat-form-field>

      <mat-form-field>
        <input matInput [matDatepicker]="dateToPicker" placeholder="截止日期" [max]="today"
               [(ngModel)]="filterForm['orderPlacedDateTo']" (dblclick)="filterForm['orderPlacedDateTo']=undefined">
        <mat-datepicker-toggle matSuffix [for]="dateToPicker"></mat-datepicker-toggle>
        <mat-datepicker #dateToPicker></mat-datepicker>
      </mat-form-field>

      <button mat-button (click)="filter()">
        <mat-icon>search</mat-icon>
        筛选
      </button>
      <button mat-button (click)="resetFilter()">
        <mat-icon>block</mat-icon>
        全部
      </button>

    </div>
  </div>

  <table mat-table class="full-width" matSort matSortActive="orderPlacedAt" matSortDirection="desc">

    <ng-container matColumnDef="index">
      <th mat-header-cell *matHeaderCellDef>#</th>
      <td mat-cell *matCellDef="let row; let index=index">
        {{index + 1 }}&nbsp;
      </td>
    </ng-container>

    <ng-container matColumnDef="baseCcy">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>基础币种</th>
      <td class="ccy-logo-code" mat-cell *matCellDef="let row">
        <img class="ccy-logo" [src]="CoinLogoPath(row.baseCcy)" alt="">
        <div class="ccy-code">{{row.baseCcy}}</div>
      </td>
    </ng-container>

    <ng-container matColumnDef="quoteCcy">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>报价币种</th>
      <td class="ccy-logo-code" mat-cell *matCellDef="let row">
        <img class="ccy-logo" [src]="CoinLogoPath(row.quoteCcy)" alt="">
        <div class="ccy-code">{{row.quoteCcy}}</div>
      </td>
    </ng-container>

    <ng-container matColumnDef="ex">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>交易所</th>
      <td mat-cell *matCellDef="let row">
        {{row.ex}}
      </td>
    </ng-container>

    <ng-container matColumnDef="symbol">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>交易对</th>
      <td mat-cell *matCellDef="let row">
        {{row.symbol}}
      </td>
    </ng-container>

    <ng-container matColumnDef="type">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>类型</th>
      <td mat-cell *matCellDef="let row">
        {{getTypeLabel(row.type)}}
      </td>
    </ng-container>

    <ng-container matColumnDef="watchDirection">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>关注价格方向</th>
      <td mat-cell *matCellDef="let row">
        {{row.watchDirection}}
      </td>
    </ng-container>

    <ng-container matColumnDef="side">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>方向</th>
      <td mat-cell *matCellDef="let row"
          [class.order-side-buy]="row.side==='buy'"
          [class.order-side-sell]="row.side==='sell'">
        {{row.side}}
      </td>
    </ng-container>

    <ng-container matColumnDef="basePoint">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>基点</th>
      <td mat-cell *matCellDef="let row">{{row.basePoint | effectdigits}}</td>
    </ng-container>

    <ng-container matColumnDef="expectingPoint">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>期望</th>
      <td mat-cell *matCellDef="let row">{{row.expectingPoint | effectdigits}}</td>
    </ng-container>

    <ng-container matColumnDef="peak">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>已达峰值</th>
      <td mat-cell *matCellDef="let row">
        {{row.peak | effectdigits}}<br>
        <span class="subordinated">{{row.peakTime | date:'MM-dd HH:mm'}}</span>
      </td>
    </ng-container>

    <ng-container matColumnDef="valley">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>已达谷值</th>
      <td mat-cell *matCellDef="let row">
        {{row.valley | effectdigits}}<br>
        <span class="subordinated">{{row.valleyTime | date:'MM-dd HH:mm'}}</span>
      </td>
    </ng-container>

    <ng-container matColumnDef="executor">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>执行器</th>
      <td mat-cell *matCellDef="let row">
        {{row.executor}}
      </td>
    </ng-container>

    <ng-container matColumnDef="clientOrderId">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>客户订单号</th>
      <td mat-cell *matCellDef="let row">{{row.clientOrderId}}</td>
    </ng-container>

    <ng-container matColumnDef="orderPlacedAt">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>下单时间</th>
      <td mat-cell *matCellDef="let row">
        {{row.orderPlacedAt | date:'MM-dd HH:mm'}}
      </td>
    </ng-container>

    <ng-container matColumnDef="actions">
      <th mat-header-cell *matHeaderCellDef></th>
      <td mat-cell *matCellDef="let row" align="end">
        <button mat-button (click)="showStrategyDetail(row)">
          <mat-icon>schedule</mat-icon>
          策略
        </button>
        <button mat-button (click)="showOrderDetail(row)" *ngIf="row.clientOrderId">
          <mat-icon>list</mat-icon>
          订单
        </button>
      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
  </table>

  <mat-paginator #paginator
                 [length]="dataSource?.total"
                 [pageIndex]="0"
                 [pageSize]="20"
                 [pageSizeOptions]="[10, 20, 50, 100]">
  </mat-paginator>

</div>

<p>&nbsp;</p>
